package com.example.myanimator.one;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @author tgw
 * @date 2021/3/16
 * @describe
 */
class DrawPath extends View {

    private Paint mPaint;
    private Path mPath;
    private Canvas mCanvas;

    public DrawPath(Context context) {
        super(context);
    }

    public DrawPath(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true); // 去除锯齿
        mPaint.setStrokeWidth(5);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.WHITE);
        mPath = new Path();
        mCanvas = new Canvas();

    }

    @Override
    protected void onDraw(Canvas canvas) {

        mPath.moveTo(10,10);
        mPath.lineTo(20,10);
        mPath.arcTo(new RectF(20,10,60,50),0,359);
        //addArc 函数可以直接添加路径 不必考虑之前的路径形状
        mPath.addArc(new RectF(100,10,150,60),0,-359);
        mPath.addRect(new RectF(100,10,150,60), Path.Direction.CCW);//逆时针
        mPath.addRect(new RectF(200,10,250,60), Path.Direction.CW);//顺时针
      canvas.drawPath(mPath,mPaint);

        mPath.reset();
        mPaint.setTextSize(32);
        mPath.moveTo(500,10);
        //画文字
        mPath.addRect(new RectF(300,10,350,80), Path.Direction.CW);//顺时针
        canvas.drawPath(mPath,mPaint);
        canvas.drawTextOnPath("天天天向上",mPath,0,30,mPaint);

    }
}
